package edu.cmu.cs.stage3.alice.authoringtool.util;

import edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources;
import edu.cmu.cs.stage3.alice.core.reference.PropertyReference;

/**
 * @author Jason Pratt
 */
public class PropertyReferenceListCellRenderer extends javax.swing.DefaultListCellRenderer {
	//Rem @Override
	public java.awt.Component getListCellRendererComponent( javax.swing.JList list, Object value, int index, boolean isSelected, boolean cellHasFocus ) {
		setComponentOrientation( list.getComponentOrientation() );

		if( isSelected ) {
			setBackground( list.getSelectionBackground() );
			setForeground( list.getSelectionForeground() );
		} else {
			setBackground( list.getBackground() );
			setForeground( list.getForeground() );
		}
		if( value instanceof PropertyReference ) {
			PropertyReference reference = (PropertyReference)value;
			String text = "";
			if( reference.getProperty() instanceof edu.cmu.cs.stage3.alice.core.property.ObjectArrayProperty ) {
				text = AuthoringToolResources.getReprForValue( reference.getProperty().getOwner(), true ) + "." + reference.getProperty().getName() + "[" + index + "] -> " + AuthoringToolResources.getReprForValue( reference.getProperty().get(), true );
			} else {
				text = AuthoringToolResources.getReprForValue( reference.getProperty().getOwner(), true ) + "." + reference.getProperty().getName() + " -> " + AuthoringToolResources.getReprForValue( reference.getProperty().get(), true );
			}
			setIcon( null );
			setText( text );



		} else if( value instanceof javax.swing.Icon ) {
			setIcon( (javax.swing.Icon)value );
			setText( "" );
		} else {
			setIcon( null );
			setText( ( value == null ) ? "" : value.toString() );
		}

		setEnabled( list.isEnabled() );
		setFont( list.getFont() );
		setBorder( ( cellHasFocus ) ? javax.swing.UIManager.getBorder( "List.focusCellHighlightBorder" ) : noFocusBorder );

		return this;
	}
}